package room

import (
	"errors"
	"server/common"

	"github.com/sirupsen/logrus"
)

// -------------------------------------------------------------------------------------------------
//
// -------------------------------------------------------------------------------------------------
func ValidateMediaInfo(media common.MediaInfo) error {
	if media.MediaType == "" {
		return errors.New("media type cannot be empty")
	}
	if media.MediaId == "" {
		return errors.New("media ID cannot be empty")
	}
	if media.MediaName == "" {
		return errors.New("media name cannot be empty")
	}
	if media.SrcType == "" {
		return errors.New("media source type cannot be empty")
	}
	if media.SrcId == "" {
		return errors.New("media source ID cannot be empty")
	}
	if media.SrcName == "" {
		return errors.New("media source name cannot be empty")
	}

	return nil
}

// -------------------------------------------------------------------------------------------------
//
// -------------------------------------------------------------------------------------------------
func LOG(rid ...string) *logrus.Entry {
	return common.Logger(common.SERVICE_TYPE_ROOM, rid...)
}

////////////////////////////////////////////////////////////////////////////////////////////////////

type RoomDispatcher struct {
	FromService common.ServiceInfo
	ToService   common.ServiceInfo
	Dispatcher  common.IMsgDispatcher
}

func (rd *RoomDispatcher) Dispatch(msg common.Message, connId string) error {
	return rd.Dispatcher.Dispatch(msg, rd.FromService, rd.ToService, connId)
}

func (rd *RoomDispatcher) DispatchSync(msg common.Message, connId string, resCmd string) (*common.Message, error) {
	return rd.Dispatcher.DispatchSync(msg, rd.FromService, rd.ToService, connId, resCmd)
}

func (rd *RoomDispatcher) DispatchWait(msg common.Message, connId string, resCmd string) error {
	return rd.Dispatcher.DispatchWait(msg, rd.FromService, rd.ToService, connId, resCmd)
}
